#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
    int data;
    struct node* next;
}LNode;

void SlistPushback(LNode**phead,int x)
{
    LNode* Tail=*phead;
    LNode* newnode;
    newnode=(LNode*)malloc(sizeof(LNode));
    newnode->data=x;
    newnode->next=NULL;
    if(*phead==NULL)
    {
        *phead=newnode;

    }
    else
    {
    while(Tail->next!=NULL)
    {
        Tail=Tail->next;
    }
    Tail->next=newnode;
    }
}

int main()
{
    int x,s=0;
    LNode* plist;
    plist=NULL;
    while(~scanf("%d",&x)&&x)
    {
        s++;
        SlistPushback(&plist,x);
    }
        LNode* cur=plist;
        while(cur!=NULL)
        {
            printf("%d  ",cur->data);
            cur=cur->next;
        }
        printf("\n");
        printf("%d",s);
    return 0;
}
